﻿using MediatR;
using Traceability.APP.Applications.Commands.YangZhi;
using Traceability.Domain;
using Traceability.ErrorCode;
using Traceability.Infrastructure;

namespace Traceability.APP.Applications.CommandHandlers.YangZhi
{
    public class HealthQueryCommandHandler : IRequestHandler<HealthQueryCommand, APIResult<List<HealthModel>>>
    {
        private readonly IBaseRepository<HealthModel> _healthRepository;

        public HealthQueryCommandHandler(IBaseRepository<HealthModel> healthRepository)
        {
            _healthRepository = healthRepository;
        }
        /// <summary>
        /// 查询保健信息
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public Task<APIResult<List<HealthModel>>> Handle(HealthQueryCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<HealthModel>> result = new APIResult<List<HealthModel>>();
            result.Code = APIEnum.QuerySuccess;
            result.Message = APIEnum.QuerySuccess.Desc();
            var m = _healthRepository.GetAll().Where(x => x.Batch == request.Batch);
            result.Data = m.ToList();
            return Task.FromResult(result);
        }
    }
}